<template>
  <a-form :form="form" :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }">
    <a-form-item :label="componentsObject.title">
      <a-input
        v-decorator="['seniorValue', { rules: [{ validator: handlePass}], initialValue: seniorValue }]"
        @blur="handleSubmit"
        :placeholder="componentsObject.placeholder"
        autocomplete="off"
      />
    </a-form-item>
  </a-form>
</template>


<script>

import store from '@/store/index'
import formValidate from '@/utils/validate'

export default{
  name: 'DrugBaseInput',  
  components: {
    
  },
  props: {
    componentsObject: Object
  },
  data(){
    return{
      seniorValue: '',
      formLayout: 'horizontal',
      form: this.$form.createForm(this, { name: 'coordinated' }),
    }
  },

  created(){
    this.seniorValue = this.componentsObject.value
  },

  mounted(){
    
  },
      
  methods:{

    // 单行文本的自定义校验处理
    handlePass(rule, value, callback){
      for(let item of this.componentsObject.validateObj){
        let tempResult = formValidate[item.name](value, item.msg, item.regExp)
        if(tempResult !== true){
          callback(tempResult)
        }
      }
      callback()
    },

    handleSubmit() {
      this.form.validateFields((err, values) => {
        if (!err) {
          this.seniorValue = values.seniorValue
          let tempObj = {
            index: this.componentsObject.index,
            indexWrap: this.componentsObject.indexWrap,
            seniorValue: this.seniorValue,
            through: true,
            keys: this.componentsObject.keys,
          }
          this.$emit("childValueCome", tempObj)
        }else{
          let tempObj = {
            index: this.componentsObject.index,
            seniorValue: this.seniorValue,
            through: false,
            keys: this.componentsObject.keys,
          } 
          this.$emit("childValueCome", tempObj)
        }
      })
    }
  }
}
</script>



<style lang="less" scoped>

</style>